package qldc.pm.tienan.service.impl;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import qldc.pm.tienan.model.BienBanBanGiaoHoSo;
import qldc.pm.tienan.model.CongViecBanGiao;
import qldc.pm.tienan.model.DoiTuongTienAn;
import qldc.pm.tienan.model.KetQuaTrichLuc;
import qldc.pm.tienan.model.LichSuXoaAnTich;
import qldc.pm.tienan.model.PhieuThongTinVeNguoiCoTienAn;
import qldc.pm.tienan.model.TEMP_DoiTuongTienAn;
import qldc.pm.tienan.model.TEMP_PhieuThongTinVeNguoiCoTienAn;
import qldc.pm.tienan.model.TEMP_TienAn;
import qldc.pm.tienan.model.TangThu;
import qldc.pm.tienan.model.TienAn;
import qldc.pm.tienan.model.YeuCauTrichLuc;
import qldc.pm.tienan.service.base.SaoLuuTienAnLocalServiceBaseImpl;
import qldc.pm.tienan.utils.saoluudulieu.objects.BienBanBanGiaoHoSoJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.BienBanBanGiaoHoSoListJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.CongViecBanGiaoJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.CongViecBanGiaoListJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.DoiTuongTienAnJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.DoiTuongTienAnListJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.KetQuaTrichLucJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.KetQuaTrichLucListJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.LichSuXoaAnTichJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.LichSuXoaAnTichListJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.PhieuThongTinVeNguoiCoTienAnJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.PhieuThongTinVeNguoiCoTienAnListJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.TEMP_DoiTuongTienAnJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.TEMP_DoiTuongTienAnListJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.TEMP_PhieuThongTinVeNguoiCoTienAnJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.TEMP_PhieuThongTinVeNguoiCoTienAnListJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.TEMP_TienAnJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.TEMP_TienAnListJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.TangThuJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.TangThuListJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.TienAnJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.TienAnListJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.YeuCauTrichLucJAXB;
import qldc.pm.tienan.utils.saoluudulieu.objects.YeuCauTrichLucListJAXB;
import qldc.pm.tienan.utils.saoluuphuchoi.RootTienAnJAXB;
import qldc.pm.tienan.utils.saoluuphuchoi.SaoLuuUtils;

import com.liferay.portal.kernel.exception.SystemException;

/**
 * The implementation of the sao luu tien an local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link qldc.pm.tienan.service.SaoLuuTienAnLocalService} interface.
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author Brian Wing Shun Chan
 * @see qldc.pm.tienan.service.base.SaoLuuTienAnLocalServiceBaseImpl
 * @see qldc.pm.tienan.service.SaoLuuTienAnLocalServiceUtil
 */
public class SaoLuuTienAnLocalServiceImpl
    extends SaoLuuTienAnLocalServiceBaseImpl {
	 public void saoLuuDuLieu(long userId, File xmlFile) throws JAXBException, SystemException{
			if(null != xmlFile){
				RootTienAnJAXB root = new RootTienAnJAXB();
				BienBanBanGiaoHoSoListJAXB BienBanBanGiaoHoSoListListJaxb = createDataBienBanBanGiaoHoSoList();			
				root.setBienBanBanGiaoHoSoList(BienBanBanGiaoHoSoListListJaxb);
				
				CongViecBanGiaoListJAXB CongViecBanGiaoList = createDataCongViecBanGiaoList();			
				root.setCongViecBanGiaoList(CongViecBanGiaoList);

				DoiTuongTienAnListJAXB DoiTuongTienAnList = createDataDoiTuongTienAnList();			
				root.setDoiTuongTienAnList(DoiTuongTienAnList);

				KetQuaTrichLucListJAXB KetQuaTrichLucList = createDataKetQuaTrichLucList();			
				root.setKetQuaTrichLucList(KetQuaTrichLucList);

				LichSuXoaAnTichListJAXB LichSuXoaAnTichList = createDataLichSuXoaAnTichList();			
				root.setLichSuXoaAnTichList(LichSuXoaAnTichList);

				PhieuThongTinVeNguoiCoTienAnListJAXB PhieuThongTinVeNguoiCoTienAnList = createDataPhieuThongTinVeNguoiCoTienAnList();			
				root.setPhieuThongTinVeNguoiCoTienAnList(PhieuThongTinVeNguoiCoTienAnList);

				TangThuListJAXB TangThuList = createDataTangThuList();			
				root.setTangThuList(TangThuList);


				TEMP_DoiTuongTienAnListJAXB TEMP_DoiTuongTienAnList = createDataTEMP_DoiTuongTienAnList();			
				root.setTEMP_DoiTuongTienAnList(TEMP_DoiTuongTienAnList);

				TEMP_PhieuThongTinVeNguoiCoTienAnListJAXB TEMP_PhieuThongTinVeNguoiCoTienAnList = createDataTEMP_PhieuThongTinVeNguoiCoTienAnList();			
				root.setTEMP_PhieuThongTinVeNguoiCoTienAnList(TEMP_PhieuThongTinVeNguoiCoTienAnList);

				TEMP_TienAnListJAXB TEMP_TienAnList = createDataTEMP_TienAnList();			
				root.setTEMP_TienAnList(TEMP_TienAnList);

				TienAnListJAXB TienAnList = createDataTienAnList();			
				root.setTienAnList(TienAnList);
				

				YeuCauTrichLucListJAXB YeuCauTrichLucList = createDataYeuCauTrichLucList();			
				root.setYeuCauTrichLucList(YeuCauTrichLucList);
				

				
				// create JAXB context and instantiate marshaller
			    JAXBContext context = JAXBContext.newInstance(RootTienAnJAXB.class);
			    Marshaller m = context.createMarshaller();
			    
			    // Format output: indent xml file
			    //m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

			    // Write to System.out
			    //m.marshal(root, System.out);

			    // Write to File
			    m.marshal(root, xmlFile);
			  
			} else {
				System.out.println("File is empty");
			}
	   }

	private YeuCauTrichLucListJAXB createDataYeuCauTrichLucList() throws SystemException {
		YeuCauTrichLucListJAXB reult = new  YeuCauTrichLucListJAXB();
		List<YeuCauTrichLuc>  YeuCauTrichLucList =  yeuCauTrichLucPersistence.findAll();
		List<YeuCauTrichLucJAXB> jaxbs = new ArrayList< YeuCauTrichLucJAXB>();
		for (YeuCauTrichLuc c :  YeuCauTrichLucList){
			 YeuCauTrichLucJAXB cn = SaoLuuUtils.convertFormYeuCauTrichLucToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setYeuCauTrichLuc(jaxbs);
		return reult;
	}

	private TienAnListJAXB createDataTienAnList() throws SystemException {
		TienAnListJAXB reult = new  TienAnListJAXB();
		List<TienAn>  TienAnList =  tienAnPersistence.findAll();
		List<TienAnJAXB> jaxbs = new ArrayList< TienAnJAXB>();
		for (TienAn c :  TienAnList){
			 TienAnJAXB cn = SaoLuuUtils.convertFormTienAnToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setTienAn(jaxbs);
		return reult;
	}

	private TEMP_TienAnListJAXB createDataTEMP_TienAnList() throws SystemException {
		TEMP_TienAnListJAXB reult = new  TEMP_TienAnListJAXB();
		List<TEMP_TienAn>  TEMP_TienAnList =  temp_TienAnPersistence.findAll();
		List<TEMP_TienAnJAXB> jaxbs = new ArrayList< TEMP_TienAnJAXB>();
		for (TEMP_TienAn c :  TEMP_TienAnList){
			 TEMP_TienAnJAXB cn = SaoLuuUtils.convertFormTEMP_TienAnToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setTEMP_TienAn(jaxbs);
		return reult;
	}

	private TEMP_PhieuThongTinVeNguoiCoTienAnListJAXB createDataTEMP_PhieuThongTinVeNguoiCoTienAnList() throws SystemException {
		TEMP_PhieuThongTinVeNguoiCoTienAnListJAXB reult = new  TEMP_PhieuThongTinVeNguoiCoTienAnListJAXB();
		List<TEMP_PhieuThongTinVeNguoiCoTienAn>  TEMP_PhieuThongTinVeNguoiCoTienAnList =  temp_PhieuThongTinVeNguoiCoTienAnPersistence.findAll();
		List<TEMP_PhieuThongTinVeNguoiCoTienAnJAXB> jaxbs = new ArrayList< TEMP_PhieuThongTinVeNguoiCoTienAnJAXB>();
		for (TEMP_PhieuThongTinVeNguoiCoTienAn c :  TEMP_PhieuThongTinVeNguoiCoTienAnList){
			 TEMP_PhieuThongTinVeNguoiCoTienAnJAXB cn = SaoLuuUtils.convertFormTEMP_PhieuThongTinVeNguoiCoTienAnToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setTEMP_PhieuThongTinVeNguoiCoTienAn(jaxbs);
		return reult;
	}

	private TEMP_DoiTuongTienAnListJAXB createDataTEMP_DoiTuongTienAnList() throws SystemException {
		TEMP_DoiTuongTienAnListJAXB reult = new  TEMP_DoiTuongTienAnListJAXB();
		List<TEMP_DoiTuongTienAn>  TEMP_DoiTuongTienAnList =  temp_DoiTuongTienAnPersistence.findAll();
		List<TEMP_DoiTuongTienAnJAXB> jaxbs = new ArrayList< TEMP_DoiTuongTienAnJAXB>();
		for (TEMP_DoiTuongTienAn c :  TEMP_DoiTuongTienAnList){
			 TEMP_DoiTuongTienAnJAXB cn = SaoLuuUtils.convertFormTEMP_DoiTuongTienAnToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setTEMP_DoiTuongTienAn(jaxbs);
		return reult;
	}

	private TangThuListJAXB createDataTangThuList() throws SystemException {
		 TangThuListJAXB reult = new  TangThuListJAXB();
			List<TangThu>  TangThuList =  tangThuPersistence.findAll();
			List<TangThuJAXB> jaxbs = new ArrayList< TangThuJAXB>();
			for (TangThu c :  TangThuList){
				 TangThuJAXB cn = SaoLuuUtils.convertFormTangThuToJAXB(c);
				jaxbs.add(cn);
			}
			reult.setTangThu(jaxbs);
			return reult;
	}

	private PhieuThongTinVeNguoiCoTienAnListJAXB createDataPhieuThongTinVeNguoiCoTienAnList() throws SystemException {
		 PhieuThongTinVeNguoiCoTienAnListJAXB reult = new  PhieuThongTinVeNguoiCoTienAnListJAXB();
			List<PhieuThongTinVeNguoiCoTienAn>  PhieuThongTinVeNguoiCoTienAnList =  phieuThongTinVeNguoiCoTienAnPersistence.findAll();
			List<PhieuThongTinVeNguoiCoTienAnJAXB> jaxbs = new ArrayList< PhieuThongTinVeNguoiCoTienAnJAXB>();
			for (PhieuThongTinVeNguoiCoTienAn c :  PhieuThongTinVeNguoiCoTienAnList){
				 PhieuThongTinVeNguoiCoTienAnJAXB cn = SaoLuuUtils.convertFormPhieuThongTinVeNguoiCoTienAnToJAXB(c);
				jaxbs.add(cn);
			}
			reult.setPhieuThongTinVeNguoiCoTienAn(jaxbs);
			return reult;
	}

	private LichSuXoaAnTichListJAXB createDataLichSuXoaAnTichList() throws SystemException {
		 LichSuXoaAnTichListJAXB reult = new  LichSuXoaAnTichListJAXB();
			List<LichSuXoaAnTich>  LichSuXoaAnTichList =  lichSuXoaAnTichPersistence.findAll();
			List<LichSuXoaAnTichJAXB> jaxbs = new ArrayList< LichSuXoaAnTichJAXB>();
			for (LichSuXoaAnTich c :  LichSuXoaAnTichList){
				 LichSuXoaAnTichJAXB cn = SaoLuuUtils.convertFormLichSuXoaAnTichToJAXB(c);
				jaxbs.add(cn);
			}
			reult.setLichSuXoaAnTich(jaxbs);
			return reult;
	}

	private KetQuaTrichLucListJAXB createDataKetQuaTrichLucList() throws SystemException {
		 KetQuaTrichLucListJAXB reult = new  KetQuaTrichLucListJAXB();
		List<KetQuaTrichLuc>  KetQuaTrichLucList =  ketQuaTrichLucPersistence.findAll();
		List<KetQuaTrichLucJAXB> jaxbs = new ArrayList< KetQuaTrichLucJAXB>();
		for (KetQuaTrichLuc c :  KetQuaTrichLucList){
			 KetQuaTrichLucJAXB cn = SaoLuuUtils.convertFormKetQuaTrichLucToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setKetQuaTrichLuc(jaxbs);
		return reult;
	}

	private DoiTuongTienAnListJAXB createDataDoiTuongTienAnList() throws SystemException {
		// TODO Auto-generated method stub
		DoiTuongTienAnListJAXB reult = new DoiTuongTienAnListJAXB();
		List<DoiTuongTienAn> DoiTuongTienAnList = doiTuongTienAnPersistence.findAll();
		List<DoiTuongTienAnJAXB> jaxbs = new ArrayList<DoiTuongTienAnJAXB>();
		for (DoiTuongTienAn c : DoiTuongTienAnList){
			DoiTuongTienAnJAXB cn = SaoLuuUtils.convertFormDoiTuongTienAnToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setDoiTuongTienAn(jaxbs);
		return reult;
	}

	private CongViecBanGiaoListJAXB createDataCongViecBanGiaoList() throws SystemException {
		// TODO Auto-generated method stub
		CongViecBanGiaoListJAXB reult = new CongViecBanGiaoListJAXB();
		List<CongViecBanGiao> CongViecBanGiaoList = congViecBanGiaoPersistence.findAll();
		List<CongViecBanGiaoJAXB> jaxbs = new ArrayList<CongViecBanGiaoJAXB>();
		for (CongViecBanGiao c : CongViecBanGiaoList){
			CongViecBanGiaoJAXB cn = SaoLuuUtils.convertFormCongViecBanGiaoToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setCongViecBanGiao(jaxbs);
		return reult;
	}

	private BienBanBanGiaoHoSoListJAXB createDataBienBanBanGiaoHoSoList() throws SystemException {
		BienBanBanGiaoHoSoListJAXB reult = new BienBanBanGiaoHoSoListJAXB();
		List<BienBanBanGiaoHoSo> BienBanBanGiaoHoSoList = bienBanBanGiaoHoSoPersistence.findAll();
		List<BienBanBanGiaoHoSoJAXB> jaxbs = new ArrayList<BienBanBanGiaoHoSoJAXB>();
		for (BienBanBanGiaoHoSo c : BienBanBanGiaoHoSoList){
			BienBanBanGiaoHoSoJAXB cn = SaoLuuUtils.convertFormBienBanBanGiaoHoSoToJAXB(c);
			jaxbs.add(cn);
		}
		reult.setBienBanBanGiaoHoSo(jaxbs);
		return reult;
	}

}
